package all.com.jinyongqunxiax.modules;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.randy.fundation.Logger;

import net.idik.lib.slimadapter.SlimAdapter;
import net.idik.lib.slimadapter.SlimInjector;
import net.idik.lib.slimadapter.viewinjector.IViewInjector;

import java.util.Arrays;
import java.util.List;

import all.com.jinyongqunxiax.R;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class ScriptsActivity extends AppCompatActivity {
    SlimAdapter adapter = null;
    Options options;
    List<ViewModel> viewModels = Arrays.asList(
            new ViewModel("剧情", "storys.xml"),
            // new ViewModel("剧情CG", "storysCG.xml"),
            // new ViewModel("物品PY", "storysPY.xml"),
            new ViewModel("新手任务", "newbie.xml"),

            new ViewModel("角色", "roles.xml"),
            new ViewModel("地图", "maps.xml"),
            new ViewModel("门派", "menpai.xml"),
            new ViewModel("物品", "items.xml"),

            new ViewModel("触发器(全局)", "globaltrigger.xml"),
            // new ViewModel("触发器(物品)", "item_triggers.xml"),

            // new ViewModel("动画", "animations.xml"),

            new ViewModel("外功", "skills.xml"),
            new ViewModel("内功", "internal_skills.xml"),
            new ViewModel("特技", "special_skills.xml"),
            new ViewModel("奥义", "aoyis.xml"),

            new ViewModel("商店", "shops.xml"),
            new ViewModel("战斗", "battles.xml"),
            new ViewModel("提示", "resource_suggesttips.xml"),

            new ViewModel("天关", "towers.xml"),
            // new ViewModel("resource", "resource.xml"),
            new ViewModel("成长", "growtemplates.xml")
            // new ViewModel("touch", "touch.xml")
    );

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.scripts_activity);

        Intent intent = getIntent();
        options = new Options(intent);

        setTitle("Scripts");

        RecyclerView recyclerView = findViewById(R.id.scripts_components_listview);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        adapter = SlimAdapter.create().register(R.layout.scripts_component_item, new SlimInjector<ViewModel>() {
                    @Override
                    public void onInject(@NonNull ViewModel viewModel, @NonNull IViewInjector injector) {
                        injector.text(R.id.scripts_components_title, viewModel.title);
                        injector.clicked(R.id.scripts_components_title, new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                openComoponent(viewModel);
                            }
                        });
                    }
                }
        ).attachTo(recyclerView);
        adapter.updateData(viewModels);
    }

    private void openComoponent(@NonNull ViewModel viewModel) {
        String title = viewModel.title;

        switch (title) {
            case "剧情":
                startActivity(StoriesActivity.Options.intent(ScriptsActivity.this, options.mod, options.component + "/storys.xml"));
                break;
            // case "剧情CG":startActivity(StorysCGActivity.Options.intent(ScriptsActivity.this, options.mod, options.component + "/storysCG.xml"));break;
            // case "物品PY":startActivity(StorysPYActivity.Options.intent(ScriptsActivity.this, options.mod, options.component + "/storysPY.xml"));break;
            case "新手任务":
                startActivity(TasksActivity.Options.intent(ScriptsActivity.this, options.mod, options.component + "/newbie.xml"));
                break;

            case "角色":
                startActivity(RolesActivity.Options.intent(ScriptsActivity.this, options.mod, options.component + "/roles.xml"));
                break;
            case "地图":
                startActivity(MapsActivity.Options.intent(ScriptsActivity.this, options.mod, options.component + "/maps.xml"));
                break;
            case "门派":
                startActivity(MenpaisActivity.Options.intent(ScriptsActivity.this, options.mod, options.component + "/menpai.xml"));
                break;
            case "物品":
                startActivity(ItemsActivity.Options.intent(ScriptsActivity.this, options.mod, options.component + "/items.xml"));
                break;

            case "触发器(全局)":
                startActivity(TriggersActivity.Options.intent(ScriptsActivity.this, options.mod, options.component + "/globaltrigger.xml"));
                break;
            //  case "触发器(物品)":startActivity(Item_triggersActivity.Options.intent(ScriptsActivity.this, options.mod, options.component + "/item_triggers.xml"));break;
            //  case "动画":startActivity(AnimationsActivity.Options.intent(ScriptsActivity.this, options.mod, options.component + "/animations.xml"));break;

            case "外功":
                startActivity(SkillsExternalActivity.Options.intent(ScriptsActivity.this, options.mod, options.component + "/skills.xml"));
                break;
            case "内功":
                startActivity(SkillsInternalActivity.Options.intent(ScriptsActivity.this, options.mod, options.component + "/internal_skills.xml"));
                break;
            case "特技":
                startActivity(SkillsSpecialActivity.Options.intent(ScriptsActivity.this, options.mod, options.component + "/special_skills.xml"));
                break;
            case "奥义":
                startActivity(SkillsAoyiActivity.Options.intent(ScriptsActivity.this, options.mod, options.component + "/aoyis.xml"));
                break;

            case "商店":
                startActivity(ShopsActivity.Options.intent(ScriptsActivity.this, options.mod, options.component + "/shops.xml"));
                break;
            case "战斗":
                startActivity(BattlesActivity.Options.intent(ScriptsActivity.this, options.mod, options.component + "/battles.xml"));
                break;
            case "提示":
                startActivity(TipsActivity.Options.intent(ScriptsActivity.this, options.mod, options.component + "/resource_suggesttips.xml"));
                break;

            case "天关":
                startActivity(TowersActivity.Options.intent(ScriptsActivity.this, options.mod, options.component + "/towers.xml"));
                break;
            case "成长":
                startActivity(GrowsActivity.Options.intent(ScriptsActivity.this, options.mod, options.component + "/growtemplates.xml"));
                break;
            default:
                Logger.w("unhandled component %s", title);
                break;
        }
    }

    void openStorys(ViewModel viewModel) {

    }

    public static class Options {
        String mod;
        String component;
        Options(Intent intent) {
            this.mod = intent.getStringExtra("mod");
            this.component = intent.getStringExtra("component");

        }

        static Intent intent(Context context, String mod, String component) {
            Intent intent = new Intent(context, ScriptsActivity.class);
            intent.putExtra("mod", mod);
            intent.putExtra("component", component);
            return intent;
        }
    }

    private static class ViewModel {
        String title;
        String path;

        ViewModel(String title, String path) {
            this.title = title;
            this.path = path;
        }
    }
}
